var searchForm = new Vue({
  el:'#searchForm',
  data: {
    marketList:[],
    carTypeList:[],
    brandList:[],
    seriesList:[],
    modelList:[],
    shopList:[],
  },
  methods: {
 
    },
});

//市场
$.get(defaultUrl+"/controller/getMarketList?marketId="+marketId,function(res){
  searchForm.marketList = res.result;
},'json');



//车身类型
$.get(defaultUrl+"/controller/getCarTypeList",function(res){
  searchForm.carTypeList = res.result
},'json');

$.get(defaultUrl+"/controller/getBrandList",function(res){
  searchForm.brandList = res.result
  console.log(res.result)
},'json');

function getShopList(marketId){
  $.get(defaultUrl+"/controller/getShopList?marketId="+marketId,function(res){
    searchForm.shopList = res.result;
  },'json');
}
function getSeriesId(brandId){
  console.log(brandId)
  $.get(defaultUrl+"/controller/getSeriesList?brandId="+brandId,function(res){
    searchForm.seriesList = res.result
    console.log(res.result)
  },'json');
}

function getModelId(seriesId){
  $.get(defaultUrl+"/controller/getModelList?seriesId="+seriesId,function(res){
    searchForm.modelList = res.result
    console.log(res.result)
  },'json');
}

function changePrice(ele){
  var priceCode = $(ele).val();
  switch(priceCode)
    {
    case '1':
      $('input[name=fromShowPrice]').val('0');
      $('input[name=toShowPrice]').val('5');
      break;
    case '2':
      $('input[name=fromShowPrice]').val('5');
      $('input[name=toShowPrice]').val('10');
      break;
    case '3':
      $('input[name=fromShowPrice]').val('10');
      $('input[name=toShowPrice]').val('20');
      break;
    case '4':
      $('input[name=fromShowPrice]').val('20');
      $('input[name=toShowPrice]').val('30');
      break;
    case '5':
      $('input[name=fromShowPrice]').val('30');
      $('input[name=toShowPrice]').val('50');
      break;
    case '6':
      $('input[name=fromShowPrice]').val('50');
      $('input[name=toShowPrice]').val('100');
      break;
    case '6':
      $('input[name=fromShowPrice]').val('100');
      $('input[name=toShowPrice]').val('');
      break;
    default:
      return '无';
      break;
    }
}

function changeCarAge(ele){
  var priceCode = $(ele).val();
  switch(priceCode)
    {
    case '1':
      $('input[name=fromCarAge]').val('0');
      $('input[name=toCarAge]').val('1');
      break;
    case '2':
      $('input[name=fromCarAge]').val('1');
      $('input[name=toCarAge]').val('3');
      break;
    case '3':
      $('input[name=fromCarAge]').val('3');
      $('input[name=toCarAge]').val('5');
      break;
    case '4':
      $('input[name=fromCarAge]').val('5');
      $('input[name=toCarAge]').val('8');
      break;
    case '5':
      $('input[name=fromCarAge]').val('8');
      $('input[name=toCarAge]').val('10');
      break;
    case '6':
      $('input[name=fromCarAge]').val('10');
      $('input[name=toCarAge]').val('');
      break;
    default:
      return '无';
      break;
    }
}

function changeMileage(ele){
  var priceCode = $(ele).val();
  switch(priceCode)
    {
    case '1':
      $('input[name=fromMileage]').val('0');
      $('input[name=toMileage]').val('1');
      break;
    case '2':
      $('input[name=fromMileage]').val('0');
      $('input[name=toMileage]').val('3');
      break;
    case '3':
      $('input[name=fromMileage]').val('0');
      $('input[name=toMileage]').val('6');
      break;
    case '4':
      $('input[name=fromMileage]').val('0');
      $('input[name=toMileage]').val('10');
      break;
    case '5':
      $('input[name=fromMileage]').val('10');
      $('input[name=toMileage]').val('');
      break;
    default:
      return '无';
      break;
    }
}

$('#serchBtn').click(function(){
  $('.loading').show();
  var serchParams = $('#searchForm').serialize();
  console.log(serchParams);
  $.ajax({
    type: "get",      //data 传送数据类型。post 传递
    dataType: 'json',  // 返回数据的数据类型json
    url: defaultUrl+"/controller/getSaleBillNum",  // yii 控制器/方法
    cache: false,      
    data: serchParams,  //传送的数据
    error:function(){
       alert("数据传输错误");
       $('.loading').hide();
    },success: function (data) {
      console.log(data);
      if (data.code != 1) {
        return false
      }
      var pageTotal = data.result.total;
      var pageNumTotal = Math.ceil(pageTotal/20);
      $("#page").paging({
        pageNo:1,
        totalPage: pageNumTotal,
        totalSize: pageTotal,
        callback: function(num) {
          initSearchList(num,serchParams)
        }
      });
      initSearchList(1,serchParams);
    }
  });
})

function initSearchList(pageIndex,params){
  $('.loading').show();
  $.ajax({
    type: "get",      //data 传送数据类型。post 传递
    dataType: 'json',  // 返回数据的数据类型json
    url: defaultUrl+"/controller/getSaleBillList",  // yii 控制器/方法
    cache: false,      
    data: params + '&pageIndex='+pageIndex+'&pageSize=20',  //传送的数据
    error:function(){
       alert("数据传输错误");
    },success: function (data) {
      console.log(data);
      if (data.code != 1) {
        $('.loading').hide();
        return false
      }
      vm.res = data.result;
      $('.loading').hide();

    }
  });
}
























